package models.sys;

import com.alibaba.fastjson.JSONObject;

import javax.persistence.*;
import java.util.List;

/**
 * Created by zqx on 16/5/16.
 */
@Entity
@Table(name="tb_admin_role")
public class AdminRole extends BaseSystemModel {

    public String role;
    public String description;

    @ManyToMany(cascade= CascadeType.ALL)
    @JoinTable(
        name = "tb_admin_role_menu",
        joinColumns = @JoinColumn(name = "role_id"),
        inverseJoinColumns = @JoinColumn(name = "menu_id")
    )
    @OrderBy("parent,sortid DESC")
    public List<AdminMenu> menus;

    public JSONObject getInfo(){
        JSONObject info = new JSONObject();
        info.put("role",this.role);
        info.put("description",this.description);
        info.put("enabled",this.enabled);
        info.put("id",this.id);
        return info;
    }

}
